package com.tools.service.login.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.tools.pojo.login.dto.LoginDTO;
import com.tools.pojo.login.vo.LoginVO;
import com.tools.pojo.user.po.User;
import com.tools.service.login.LoginService;
import com.tools.service.user.UserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@AllArgsConstructor
public class LoginServiceImpl implements LoginService {

    private final UserService userService;

    @Override
    public LoginVO login(LoginDTO loginDTO) {
        User user = userService.verifyUser(loginDTO);

        //查询用户权限
//        String userType = user.getUsersRole();


        LoginVO loginVO = new LoginVO();
        loginVO.setUserId(user.getId());
        loginVO.setUsername(user.getUsername());
        loginVO.setNickname(user.getNickname());
//        loginVO.setUsersRole();
        loginVO.setUserType(user.getUserType());
        loginVO.setUser(user);
        return loginVO;
    }

    @Override
    public Boolean logout() {
        StpUtil.logout();
        return true;
    }


}
